package iotest;

import java.io.*;
import java.nio.charset.StandardCharsets;
import java.util.Scanner;

public class Test01 {
    public static void main(String[] args) {
        //
        FileOutputStream fos= null;//可追加
        try {
            fos = new FileOutputStream("node.txt",true);
        } catch (FileNotFoundException e) {
            throw new RuntimeException(e);
        }
        OutputStreamWriter osw=new OutputStreamWriter(fos, StandardCharsets.UTF_8);
        BufferedWriter bw=new BufferedWriter(osw);
        PrintWriter pw=new PrintWriter(bw,true);//自动冲水
        Scanner scan=new Scanner(System.in);
        System.out.println("请输入内容:");
        while (true){
            String str=scan.nextLine();
            if ("exit".equalsIgnoreCase(str)){
                break;
            }
            pw.println(str);
            //由于PrintWriter pw=new PrintWriter(bw,true);//自动冲水
            //第二个参数true,所以可以自动冲水
        }
        System.out.println("写入完毕!");
        pw.close();
    }
}
